/**
 * 
 */
package ar.edu.utn.frsf.cidisi.ginet.generation.upcolbpip2cginet.elementstemplate;

import org.eclipse.emf.common.util.EList;
import org.pnml.tools.epnk.pnmlcoremodel.AnnotationGraphics;
import org.pnml.tools.epnk.pnmlcoremodel.Coordinate;
import org.pnml.tools.epnk.pnmlcoremodel.Name;
import org.pnml.tools.epnk.pnmlcoremodel.PnmlcoremodelFactory;
import org.pnml.tools.epnk.pntypes.hlpng.pntd.hlpngdefinition.Declaration;

import ar.edu.utn.frsf.cidisi.ginet.abstractginet.Arc;
import ar.edu.utn.frsf.cidisi.ginet.abstractginet.Place;
import ar.edu.utn.frsf.cidisi.ginet.abstractginet.RefPlace;
import ar.edu.utn.frsf.cidisi.ginet.abstractginet.Transition;
import ar.edu.utn.frsf.cidisi.upcolbpip.interactionprotocols.BusinessMessage;
import ar.edu.utn.frsf.cidisi.upcolbpip.interactionprotocols.InteractionProtocolElement;

/**
 * @author Neri
 *
 */
public class BusinessMessageUpcolbpipStructure extends ChoreographyStructure {
	
	public BusinessMessageUpcolbpipStructure(Integer i){		
		super();
		this.pos = i;
		//Name		
		AnnotationGraphics graphicsName = PnmlcoremodelFactory.eINSTANCE
				.createAnnotationGraphics();
		
		Name nameLabel = PnmlcoremodelFactory.eINSTANCE.createName();
		
		Coordinate coordinate2 = PnmlcoremodelFactory.eINSTANCE.createCoordinate();
		
		coordinate2.setX(-9);
		coordinate2.setY( -39);
		
		graphicsName.setOffset(coordinate2);
		
		nameLabel.setText("BUSINESSMESSAGE");
		nameLabel.setGraphics(graphicsName);
		
		this.abstractPage.setName(nameLabel);
	}
	
	@Override
	public void createPageStructure(InteractionProtocolElement element, Place placeIn, Place placeOut, EList<Declaration> ginetDeclarations, Place termination, EList<BusinessMessage> messages){		
		
		this.fillVarDeclAndNameSort(ginetDeclarations);
		
		this.setPageName(element);
		
		RefPlace refPlaceIn = this.createRefPlace("InPlace",  1, 2, "InPlace", -4, -4, "1", placeIn);

		String nameBM = "businessmessage";
		if(element.getName() != null){
			nameBM = element.getName();
		}
		Transition transitionBM = this.createTransition(nameBM, 2, 2, nameBM, -4, -9, "1", "1", null);
		Arc arcPInTbm = this.createArc("", this.getVarDec("gi"), -37, -3, refPlaceIn, transitionBM);

		RefPlace refPlaceOut = this.createRefPlace("OutPlace", 3, 2, "OutPlace", -4, -4, "1", placeOut);
		Arc arcTbmPOut= this.createArc("", this.getVarDec("gi"), -9, -19, transitionBM, refPlaceOut);
		
		this.abstractPage.getObject().add(refPlaceIn);
		this.abstractPage.getObject().add(refPlaceOut);
		
		this.abstractPage.getObject().add(transitionBM);
		
		this.abstractPage.getObject().add(arcPInTbm);
		this.abstractPage.getObject().add(arcTbmPOut);		
	}
}